package com.company.cloud.behavior.modules.app.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.company.cloud.behavior.modules.app.controller.req.FollowDataStaticParam;
import com.company.cloud.behavior.modules.app.controller.req.FollowSaveParam;
import com.company.cloud.behavior.modules.app.controller.resp.FollowDataStaticModel;
import com.company.cloud.behavior.modules.base.entity.UserFollowInfo;
import com.company.cloud.behavior.modules.base.service.UserFollowInfoService;
import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.auth.annotation.Login;
import com.company.cloud.common.bean.BaseClientResult;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.constant.BaseConstant;
import com.company.cloud.common.utils.AuthContextUtils;
import com.company.cloud.user.modules.api.response.UserSimple;
import com.company.cloud.user.modules.api.service.UserRemoteService;
import com.company.common.server.constant.IRelBusiType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 关注统计数据
 */
@Login
@RestController
@RequestMapping("/app/behavior/data/follow")
@Api(tags="App_Behavior_关注统计数据")
public class FollowDataController {


    @Autowired
    private UserFollowInfoService userFollowInfoService;
    @Autowired
    private UserRemoteService userRemoteService;



    @PostMapping("/followDataStatic")
    @ApiOperation(value="关注统计",response = FollowDataStaticModel.class )
    public BaseResult followDataStatic(@RequestBody FollowDataStaticParam params) {
        ValidatorUtils.validate(params);


        //			BaseClientResult<UserSimple> userSimpleResult = userRemoteService.getUserById(params.getFollowUserId());
//			UserSimple userSimple= BaseClientResult.getResultData(userSimpleResult);
//
//			if(userSimple!=null && StrUtil.isNotEmpty(userSimple.getCustType()) && StrUtil.isNotEmpty(userSimple.getCustCode())){
//			}


        int num= userFollowInfoService.count(new QueryWrapper<UserFollowInfo>()
                .eq("obj_type",params.getObjType())
                .eq("obj_no",params.getObjNo())
                .eq("obj_is_updown", BaseConstant.YNEnum.YES.getCode())
                .eq("rows_state",BaseConstant.EnabledEnum.ENABLED.getCode())
        );


        FollowDataStaticModel data = new FollowDataStaticModel(params.getObjType(),params.getObjNo(),params.getObjImg());
        data.setConcernedNum(num);
        data.setFocusQuantity(null);


//        if(IRelBusiType.PTY_Artist_ObjType.equals(params.getObjType())){
//            BaseClientResult<UserSimple> userSimpleResult= userRemoteService.getUserByCustCode(params.getObjNo());
//            UserSimple userSimple=BaseClientResult.getResultData(userSimpleResult);
//            if(userSimple!=null){
//                int num2= userFollowInfoService.count(new QueryWrapper<UserFollowInfo>()
//                        .eq("user_id",userSimple.getId())
//                        .eq("obj_is_updown", BaseConstant.YNEnum.YES.getCode())
//                        .eq("rows_state",BaseConstant.EnabledEnum.ENABLED.getCode())
//                );
//                data.setFocusQuantity(num2);
//            }
//        }

        if(IRelBusiType.UC_User_ID.equals(params.getObjType())){
            Integer objIdInt= Convert.toInt(params.getObjNo());
            int num2= userFollowInfoService.count(new QueryWrapper<UserFollowInfo>()
                    .eq("user_id",objIdInt)
                    .eq("obj_is_updown", BaseConstant.YNEnum.YES.getCode())
                    .eq("rows_state",BaseConstant.EnabledEnum.ENABLED.getCode())
            );
            data.setFocusQuantity(num2);
        }

//        if(IRelBusiType.UC_Company_ID.equals(params.getObjType())){
//            data.setFocusQuantity(null);
//        }

        return  BaseResult.ok(data);
    }











}
